﻿using EmgrMvc.BLL;
using EmgrMvc.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace EmgrMvc.Api
{
    [Route("api/[controller]")]
    [ApiController]
    public class AppController : ControllerBase
    {
        private readonly MyContext _context;

        public AppController(MyContext context)
        {
            _context = context;
        }
        // GET: api/<AppController>
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/<AppController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value";
        }

        // POST api/<AppController>
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/<AppController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<AppController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }

        // POST api/<AppController>/reset/schedule
        [HttpPost("reset/schedule")]
        public void ResetSchedule()
        {
            MqttTool tool = MqttTool.getSingleton();
            tool.ResetSchedule();
        }

        // POST api/<AppController>/group/on/{id}
        [HttpPost("group/on/{id}")]
        public void GroupOn(int id)
        {
            EsysBLL serv = new EsysBLL(_context);
            serv.PowerOnByGroup(id);
        }

        // POST api/<AppController>/group/off/{id}
        [HttpPost("group/off/{id}")]
        public void GroupOff(int id)
        {
            EsysBLL serv = new EsysBLL(_context);
            serv.PowerOffByGroup(id);
        }

        // POST api/<AppController>/device/on/{id}
        [HttpPost("device/on/{id}")]
        public void DeviceOn(int id)
        {
            EsysBLL serv = new EsysBLL(_context);
            serv.PowerOnDevice(id);
        }

        // POST api/<AppController>/device/off/{id}
        [HttpPost("device/off/{id}")]
        public void DeviceOff(int id)
        {
            EsysBLL serv = new EsysBLL(_context);
            serv.PowerOffDevice(id);
        }
    }
}
